package com.example.completableFutureDemo.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * <pre>
 * 功能描述：
 * </pre>
 *
 * @author: 李明杰
 * @date: 2023/4/28 15:05
 */
@Component
@Slf4j
public class RunningTask {
    @Async("taskExecutor")
    public void voidTask() throws InterruptedException {
        log.info("look at the thread");
        throw new RuntimeException();
//        Thread.sleep(2000);
    }

    public boolean boolTask() throws InterruptedException {
        log.info("look at the thread");
        throw new RuntimeException();
//        Thread.sleep(2000);
//        return true;
    }

    @Async("taskExecutor")
    public Future<Boolean> futureTask() throws InterruptedException {
        log.info("look at the thread");
        return new AsyncResult<>(boolTask());
    }
}
